package adc.app.ui.wicket.table;

import org.apache.wicket.Component;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.markup.html.form.Check;
import org.apache.wicket.markup.html.form.CheckGroupSelector;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;

public class CheckColumn<T> extends AbstractColumn<T> {

	private static final long serialVersionUID = 1L;
	
	private static final String ID_CHECK = "chk";

	public CheckColumn(String sortProperty) {
		super(null, sortProperty);
	}

	public CheckColumn() {
		this(null);
	}

	@Override
	public void populateItem(Item<ICellPopulator<T>> cellItem, String componentId, IModel<T> rowModel) {
		cellItem.add(createCheckPanel(componentId).add(new Check<T>(ID_CHECK, createCheckModel(rowModel))));		
	}

	@Override
	public Component getHeader(String componentId) {
		return createCheckPanel(componentId).add(new CheckGroupSelector(ID_CHECK));
	}

	protected IModel<T> createCheckModel(IModel<T> rowModel) {
		return rowModel;
	}
	
	protected CheckPanel createCheckPanel(String id) {
		return new CheckPanel(id);
	}
}
